using Catalog.Application.Categorys.Interfaces;
using Catalog.Domain.Entities;
using Microsoft.EntityFrameworkCore;


namespace Catalog.Infrastructure.Repositories
{
    public class CategoryRepository : ICategoryRepository
    {
        private readonly CatalogDbContext _context;
        public CategoryRepository(CatalogDbContext context)
        {
            _context = context;
        }

        public void Add(Category entity)
        {
            _context.Categories.Add(entity);
        }

        public Task<Category?> GetByIdAsync(Guid id, CancellationToken cancellationToken = default)
        {
            return _context.Categories
                .FirstOrDefaultAsync(x => x.Id == id, cancellationToken);
        }

        public void Remove(Category entity)
        {
            _context.Categories.Remove(entity);
        }
    }
}